package com.jykj.modbus.equipment.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * @ClassName HttpResponse
 * @Description TODO
 * @Author lx
 * @Date 2019/1/5 11:54
 * @Version 1.0
 **/
@Getter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class HttpResponse<T> {
    /**
     * 102:失败 101:成功 103:超时
     */
    private int ret_code;

    /**
     * 返回的消息
     */
    private String message;

    /**
     * 各种类型的数据
     */
    private T data;

    public HttpResponse() {
    }

    public HttpResponse(int ret_code, String message, T data) {
        this.ret_code = ret_code;
        this.message = message;
        this.data = data;
    }

    public static HttpResponse success() {
        return new HttpResponse<>(101, "成功", null);
    }

    public static HttpResponse success(final String msg) {
        return new HttpResponse<>(101, msg, null);
    }

    public static <T> HttpResponse<T> success(final T data) {
        return new HttpResponse<>(101, "成功", data);
    }

    public static <T> HttpResponse success(final String msg, final T data) {
        return new HttpResponse<>(101, msg, data);
    }

    public static HttpResponse fail() {
        return new HttpResponse<>(102, "失败", null);
    }

    public static HttpResponse fail(final String msg) {
        return new HttpResponse<>(102, msg, null);
    }

    public static <T> HttpResponse fail(final T data) {
        return new HttpResponse<>(102, "失败", data);
    }

    public static <T> HttpResponse fail(final String msg, final T data) {
        return new HttpResponse<>(102, msg, data);
    }

    public static HttpResponse timeOut() {
        return new HttpResponse<>(103, "请求超时", null);
    }

    public static HttpResponse timeOut(final String msg) {
        return new HttpResponse<>(103, msg, null);
    }

    public static <T> HttpResponse timeOut(final T data) {
        return new HttpResponse<>(103, "请求超时", data);
    }

    public static <T> HttpResponse timeOut(final String msg, final T data) {
        return new HttpResponse<>(103, msg, data);
    }

    public static HttpResponse noLogin() {
        return new HttpResponse<>(104, "登录失效，请重新登录！", null);
    }

    public static HttpResponse noLogin(final String msg) {
        return new HttpResponse<>(104, msg, null);
    }

    public static <T> HttpResponse noLogin(final T data) {
        return new HttpResponse<>(104, "登录失效，请重新登录！", data);
    }

    public static <T> HttpResponse noLogin(final String msg, final T data) {
        return new HttpResponse<>(104, msg, data);
    }

    public static <T> HttpResponse role(final String msg, final T data) {
        return new HttpResponse<>(105, msg, data);
    }
}
